package com.example.function.pool.controller;

import com.example.common.support.AjaxResponse;
import com.example.common.support.CP_GlobalNamingConstant;
import com.example.common.support.CP_OperateLog;
import com.example.function.pool.model.one.CarModel;
import com.example.function.pool.service.ICarModelService;
import com.example.function.sys.model.one.SysUser;
import com.example.function.sys.service.ISysUserService;
import com.example.support.CP_AuthenticationUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


/**
 * Description: <车型模块controller >. <br>
 * <p>
 * <车型基本的crud>
 * </p>
 * generate time:2021-7-26 15:43:23
 *
 * @author hanqf
 * @version V1.0
 */

@RestController
@Slf4j
@RequestMapping("/pool")
public class CarModelController {


    @Resource(name = "carModelService")
    protected ICarModelService carModelService;

    @Autowired
    private ISysUserService sysUserService;


    /**
     * 查询全部车型.
     *
     * @return AjaxResponse
     */
    @RequestMapping(value = "/carmodels")
    @CP_OperateLog(value = "车型查询", type = CP_GlobalNamingConstant.OPERATE_LIST)
    public AjaxResponse carModels() {
        final List<CarModel> carModelList = carModelService.findAll();
        return AjaxResponse.success(carModelList);
    }

    /**
     * 查询当前用户创建的，并且尚未关联任何项目的车型列表
     *
     * @return AjaxResponse
     */
    @RequestMapping(value = "/user/noProj/carmodels")
    @CP_OperateLog(value = "车型查询——未关联项目", type = CP_GlobalNamingConstant.OPERATE_LIST)
    public AjaxResponse noProj_carModels() {
        final SysUser sysUser = sysUserService.findByLoginName(CP_AuthenticationUtils.getUserLoginName());

        final List<CarModel> carModelList = carModelService.findAllNoProjByUserId(sysUser.getId());
        return AjaxResponse.success(carModelList);
    }


}

